import axios from 'axios'
import { message as antdMessage } from 'antd'

export const request = axios.create({
	timeout: 5000
})


request.interceptors.request.use((config) => {
	return config
}, error => {
	return Promise.reject(error)
})

request.interceptors.response.use((response) => {
	const { code, message } = response.data;
	if (code === 200) {
		antdMessage.success(message)
	}
	if (code === 400) {
		antdMessage.error(message)
	}
	return response
}, error => {
	const { status } = error.response
	const { message, config } = error
	if (status === 404) {
		antdMessage.error(message + ' 地址:' + config.url,)
	}
	return Promise.reject(error)
})